package com.ruoyi.yfdw.service.impl;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.yfdw.domain.Dict;
import com.ruoyi.yfdw.mapper.DictMapper;
import com.ruoyi.yfdw.service.IDictService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author : zll
 * @date : 2024/11/2 19:53/**
 * @BelongsProject: ruoyi
 * @BelongsPackage: com.ruoyi.yfdw.service.impl
 * @Description: TODO
 * @Author: zll
 * @CreateTime: 2024/11/02 19:53
 * @Version 1.0
 **/
@Service
@DataSource(DataSourceType.SLAVE)
public class DictServiceImpl implements IDictService {

    @Autowired
    private DictMapper dictMapper;

    /**
     * @param dict
     * @param pageNum
     * @param pageSize
     * @return java.util.List<com.ruoyi.yfdw.domain.Dict>
     * @Description：
     * @Author: zll
     * @Date: 2024/11/2 20:01
     **/
    @Override
    public List<Dict> getList(Dict dict, Integer pageNum, Integer pageSize) {
        //解决默认分页失效问题
        if(StringUtils.isNotNull(pageNum) && StringUtils.isNotNull(pageSize)){
            PageHelper.startPage(pageNum,pageSize);
        }

        List<Dict> dicts = dictMapper.getList(dict);

        return dicts;
    }

    /**
     * TODO: 增加字典类型
     *
     * @param dict 字典类型
     * @return java.lang.Integer
     * @Author: zll
     * @Date: 2024/11/6 21:06
     **/
    @Override
    public Integer addDictType(Dict dict) {
        return dictMapper.addDictType(dict);
    }

    /**
     * TODO: 根据字典分组代码和字典代码获取字典类型信息
     *
     * @param dict 字典类型
     * @return com.ruoyi.yfdw.domain.Dict
     * @Author: zll
     * @Date: 2024/11/10 19:37
     **/
    @Override
    public Dict getDictTypeByDictGroupCodeAntDictCode(Dict dict) {
        return dictMapper.getDictTypeByDictGroupCodeAndDictCode(dict);
    }

    /**
     * TODO: 更新字典类型 联合主键不可修改
     *
     * @param dict
     * @return int
     * @Author: zll
     * @Date: 2024/11/10 19:52
     **/
    @Override
    public int updateDictType(Dict dict) {
        return dictMapper.updateDictType(dict);
    }

    /**
     * TODO: 删除字典类型 通过联合主键进行删除
     *
     * @param dict
     * @return int
     * @Author: zll
     * @Date: 2024/11/20 23:37
     **/
    @Override
    public int deleteDictType(Dict dict) {
        return dictMapper.deleteDictType(dict);
    }
}
